<script setup lang="ts">
import { computed } from 'vue'
import type { Message } from '@/types/chat'

const props = defineProps<{
  message: Message
}>()

const timeString = computed(() => {
  return props.message.timestamp.toLocaleTimeString()
})
</script>

<template>
  <div class="message-item">
    <div class="message-line">
      <span class="sender">{{ message.sender }}：</span>
      <span class="content">{{ message.content }}</span>
    </div>
    <div class="time">{{ timeString }}</div>
  </div>
</template>

<style scoped>
.message-item {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background-color: #f5f5f5;
  max-width: 80%;
  word-wrap: break-word;
}

.message-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.sender {
  font-weight: bold;
  color: #2196f3; /* 发送者固定为蓝色 */
}

.content {
  color: #333; /* 消息内容为深灰色 */
  flex: 1;
}

.time {
  font-size: 0.8em;
  color: #757575;
  margin-top: 4px;
  text-align: right;
}
</style>
